﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.ServiceModel;

namespace AsianOptionsService
{
    
    public class BasedOptions
    {
        protected int typeId = 0; //Modified

        protected int dayNum = 0;//Modified

        protected double interest = 0;//Modified

        protected double initial = 0;

        protected double exercise = 0; //12;//Modified

        protected double up = 0;

        protected double down = 0;

        protected double deltaT = 0; //(dayNum / (250.0 * (double)periods));//Modified

        protected double threshold = 0; //Modified

        protected bool isCall = true;//Modified

        protected bool isFixed = true;//Modified

        protected bool isUp = true;

        protected int isAverage = 1;

        protected int otherChoice = 1;

        protected double var = 0;

        protected int brownApproxiMethod = 0;//0:binomial method,1:0-1uniform distrution to log guass distrution generator

        protected double sigma = 0;

        public BasedOptions() { }

        public BasedOptions(int typeId, int dayNum, double interest, double initial, double exercise, double up, double down,
            double deltaT, double threshold, bool isCall, bool isFixed,bool isUp,int isAverage, int otherChoice, double var, int brownApproxiMethod)
        {
            this.typeId = typeId;

            this.dayNum = dayNum;

            this.interest = interest;

            this.initial = initial;

            this.exercise = exercise;

            this.up = up;

            this.down = down;

            this.deltaT = deltaT;

            this.threshold = threshold;

            this.isCall = isCall;

            this.isFixed = isFixed;

            this.isUp = isUp;

            this.isAverage = isAverage;

            this.otherChoice = otherChoice;

            this.var = var;

            this.brownApproxiMethod = brownApproxiMethod;
        }

        public virtual double compute_price(int runs, int periods, int clientId) { return -1; }

        public void Log(string msg, int clientId)
        {
            File.AppendAllText(@"\\viewnode\SSC\HPC140\" + Environment.GetEnvironmentVariable("CCP_JOBID") + "_" + clientId + "_output.txt", msg);
        }

        public double gaussDistribution(Random rand)
        {
            double sum = 0;
            for (int i = 0; i < 12; i++)
                sum += rand.NextDouble();
            return sum - 6.0;
        }

        public double nextPrice(double curPrice, Random rand, double sigma, double interest, double deltaT)
        {
            return Math.Exp(deltaT * (interest - 0.5 * Math.Pow(sigma, 2)) + sigma * Math.Pow(deltaT, 0.5) * gaussDistribution(rand));
        }
    }

   
   
}